"use strict";
cc._RF.push(module, '96ce8McsFhNN4tqgfUtkUPx', 'ToolsHarpoon');
// scripts/ToolsHarpoon.js

"use strict";

var t = require;
var e = module;
var o = exports;

var _i,
    n = void 0 && (void 0).__extends || (_i = function i(t, e) {
  return (_i = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _i(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    a = void 0 && (void 0).__decorate || function (t, e, o, i) {
  var n,
      a = arguments.length,
      r = a < 3 ? e : null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);else for (var s = t.length - 1; s >= 0; s--) {
    (n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
  }
  return a > 3 && r && Object.defineProperty(e, o, r), r;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var r = t("GameConstant"),
    s = t("Util"),
    l = t("CarConstant"),
    c = cc._decorator,
    d = c.ccclass,
    h = c.property,
    p = function (t) {
  function e() {
    var e = null !== t && t.apply(this, arguments) || this;
    return e.weldJoint = null, e.joint_Distance = null, e.collider = null, e.node_line = null, e.node_harpoon = null, e._gameControl = null, e._nCarSite = 0, e._carTag = 0, e.selfPos = cc.v2(0, 0), e._lineMaxLength = 0, e._lineSpeed = 0, e._timeLength = 0, e.nCurOrient = r.Car_Orientation.Default, e.bCanAttack = !0, e.bUseing = !1, e.bAnimStart = !1, e.bRetreat = !1, e.bColliderCar = !1, e.colliderInfos = {
      distance: 0,
      angle: 0
    }, e.colliderHarpoon = {
      width: 0,
      x: 0,
      angle: 0
    }, e.otherPos = cc.v2(0, 0), e;
  }

  return n(e, t), e.prototype.init = function (t, e, o, i, n, a) {
    if (this._gameControl = t, this._nCarSite = e, this.joint_Distance.connectedBody = this.getAnOtherCarBody(), this.joint_Distance.node.active = !1, this.collider.tag = i, this.weldJoint.connectedBody = a, this.node.active = !0, null == a) return this.weldJoint.node.group = "equipCarWheel", this.weldJoint.node.getComponent(cc.PhysicsCircleCollider).sensor = !1, this.joint_Distance.node.group = "equipCarWheel", void (this.joint_Distance.node.getComponent(cc.PhysicsCircleCollider).sensor = !1);
    o == r.Collide_Car_Tag.Left ? (this.node.scaleX = 1, this.node.position = n, this.selfPos = cc.v2(n.x, n.y), this.nCurOrient = r.Car_Orientation.Right, r.Cur_Game_Type == r.Game_Type.PK ? this.weldJoint.connectedAnchor = cc.v2(n.x * r.Game_Type_Scale.PK, n.y * r.Game_Type_Scale.PK) : this.weldJoint.connectedAnchor = cc.v2(n.x, n.y)) : (this.node.scaleX = -1, this.node.position = cc.v3(-n.x, n.y, n.z), this.selfPos = cc.v2(-n.x, n.y), this.nCurOrient = r.Car_Orientation.Left, r.Cur_Game_Type == r.Game_Type.PK ? this.weldJoint.connectedAnchor = cc.v2(n.x * r.Game_Type_Scale.PK, n.y * r.Game_Type_Scale.PK) : this.weldJoint.connectedAnchor = cc.v2(n.x, n.y));
    var s = l.GetCarToolsData(l.Tools_ID.Harpoon);
    this._lineMaxLength = s.lineLength, this._lineSpeed = s.speed, this._timeLength = s.time;
  }, e.prototype.onGameStart = function () {}, e.prototype.onGameOver = function () {
    this._gameControl.onHarpoon(this._nCarSite, !1);
  }, e.prototype.onGameBoutReady = function () {
    this.node.active = !1, this.destroy();
  }, e.prototype.onGameBoutStart = function () {
    var t = this;
    r.Cur_Game_Type == r.Game_Type.Auto && this.scheduleOnce(function () {
      t.onUseTools();
    }, 1);
  }, e.prototype.onGameBoutOver = function () {
    this._gameControl.onHarpoon(this._nCarSite, !1);
  }, e.prototype.onMoveLeft = function () {
    this.nCurOrient != r.Car_Orientation.Left && (this.nCurOrient = r.Car_Orientation.Left, this.bColliderCar = !1, this.bUseing = !1, this.bAnimStart = !1, this.bRetreat = !1, this.node_line.width = 38, this.node_harpoon.x = 36, this.joint_Distance.node.active = !1);
  }, e.prototype.onMoveRight = function () {
    this.nCurOrient != r.Car_Orientation.Right && (this.nCurOrient = r.Car_Orientation.Right, this.bColliderCar = !1, this.bUseing = !1, this.bAnimStart = !1, this.bRetreat = !1, this.node_line.width = 38, this.node_harpoon.x = 36, this.joint_Distance.node.active = !1);
  }, e.prototype.onCanAttack = function (t) {
    this.bCanAttack = t;
  }, e.prototype.onUseTools = function (t) {
    var e = this;
    this.bCanAttack && (this.bUseing || t && !this.isAIUseToos() || (this.bUseing = !0, this.playAudio(r.Game_Audio_ID.harpoon), this.playAni(), this.scheduleOnce(function () {
      e.bUseing = !1, e.bColliderCar = !1, e._gameControl.onHarpoon(e._nCarSite, !1), e._gameControl.onCanAttack(e._nCarSite, !0), e.joint_Distance.node.active = !1, e.bAnimStart = !1, e.bRetreat = !0;
    }, this._timeLength), this._gameControl._weaponRightView.setUseToolsState()));
  }, e.prototype.onCancelUse = function () {}, e.prototype.onDisassembly = function () {
    this.weldJoint.connectedBody = null, this.node.active = !1;
  }, e.prototype.playAni = function () {
    this.bAnimStart = !0, this.bRetreat = !1;
  }, e.prototype.update = function () {
    if (this.bColliderCar) this.setLineInfo();else {
      this.node_line.scaleX = 1, this.bAnimStart ? (this.node_line.width = this.node_line.width + this._lineSpeed, this.node_harpoon.x = this.node_harpoon.x + this._lineSpeed, this.node_line.width > this._lineMaxLength && (this.bAnimStart = !1, this.bRetreat = !0)) : this.bRetreat && (this.node_line.width = this.node_line.width - this._lineSpeed, this.node_harpoon.x = this.node_harpoon.x - this._lineSpeed, this.node_line.width < this._lineSpeed && (this.node_line.width = 38, this.node_harpoon.x = 36, this.bAnimStart = !1, this.bRetreat = !1));
      var t = this.getAngle();
      t < 20 && t > -20 && (this.node_line.angle = -t, this._nCarSite == r.Car_Site.Left ? this.node_line.angle = -t : this._nCarSite == r.Car_Site.Right && (this.node_line.angle = t));
    }
  }, e.prototype.setLineInfo = function () {
    var t = this.getCarsDistance(),
        e = t.distance - this.colliderInfos.distance;
    this.node_line.width = this.colliderHarpoon.width + e, this.node_harpoon.x = this.colliderHarpoon.x + e;
    var o = this.getAngle();
    this._nCarSite == r.Car_Site.Left ? this.nCurOrient == r.Car_Orientation.Right ? (this.node_line.scaleX = 1, this.node_line.angle = -o - t.angle) : (this.node_line.scaleX = -1, this.node_line.angle = o + t.angle) : this._nCarSite == r.Car_Site.Right && (this.node_line.angle = o + t.angle);
  }, e.prototype.getAnOtherCarBody = function () {
    var t = null;
    return this._nCarSite == r.Car_Site.Left ? t = this._gameControl._carRightView.getRigidBody() : this._nCarSite == r.Car_Site.Right && (t = this._gameControl._carLeftView.getRigidBody()), t;
  }, e.prototype.getAngle = function () {
    return this._nCarSite == r.Car_Site.Right ? this._gameControl._carRightView.getAngle() : this._nCarSite == r.Car_Site.Left ? this._gameControl._carLeftView.getAngle() : 0;
  }, e.prototype.onPlayHarpoon = function (t) {
    if (this.bAnimStart && !this.bColliderCar) {
      var e = null;
      this._nCarSite == r.Car_Site.Right ? e = this._gameControl._carLeftView.getCarToNodedPos(t) : this._nCarSite == r.Car_Site.Left && (e = this._gameControl._carRightView.getCarToNodedPos(t)), console.log("碰撞"), this.otherPos = e, this.colliderInfos = this.getCarsDistance(), this.joint_Distance.connectedAnchor = cc.v2(e.x * r.Game_Type_Scale.PK, e.y * r.Game_Type_Scale.PK), this.colliderHarpoon.width = this.node_line.width, this.colliderHarpoon.angle = this.node_line.angle, this.colliderHarpoon.x = this.node_harpoon.x, this.bColliderCar = !0, this._gameControl.onHarpoon(this._nCarSite, !0), this._gameControl.onCanAttack(this._nCarSite, !1), this.joint_Distance.node.active = !0;
    }
  }, e.prototype.getCarsDistance = function () {
    if (this._nCarSite == r.Car_Site.Left) {
      var t = this._gameControl._carLeftView.getCarToWorldPos(this.selfPos),
          e = this._gameControl._carRightView.getCarToWorldPos(this.otherPos),
          o = s.Util.GetPointAngle(t, e),
          i = t.sub(e).mag(),
          n = 180 * o / Math.PI;

      return {
        distance: i / r.Game_Type_Scale.PK,
        angle: n
      };
    }

    if (this._nCarSite == r.Car_Site.Right) return e = this._gameControl._carRightView.getCarToWorldPos(this.selfPos), t = this._gameControl._carLeftView.getCarToWorldPos(this.otherPos), o = s.Util.GetPointAngle(t, e), i = t.sub(e).mag(), n = 180 * o / Math.PI, {
      distance: i / r.Game_Type_Scale.PK,
      angle: n
    };
  }, e.prototype.isAIUseToos = function () {
    var t = this._gameControl._carLeftView.getCarWorldPos(),
        e = this._gameControl._carRightView.getCarWorldPos();

    return e.x > t.x && e.x - t.x < this._lineMaxLength * r.Cur_Game_Scale;
  }, e.prototype.playAudio = function (t) {
    this._gameControl.playAudio(t);
  }, a([h(cc.WeldJoint)], e.prototype, "weldJoint", void 0), a([h(cc.DistanceJoint)], e.prototype, "joint_Distance", void 0), a([h(cc.CircleCollider)], e.prototype, "collider", void 0), a([h(cc.Node)], e.prototype, "node_line", void 0), a([h(cc.Node)], e.prototype, "node_harpoon", void 0), a([d], e);
}(cc.Component);

o["default"] = p;

cc._RF.pop();